const {verifyToken} = require('../utils/gettoken.js');
//登录的验证 
exports.testLogin = (req,res,next) => {
    const {username,password} = req.body
    if(!username || !password){
        next(4)
        return
    }
    next()
}

// 修改密码的验证  
exports.testRpwd = (req,res,next) => {
    const {id,oldpassword,newpassword} = req.body
    if(!id || !oldpassword || !newpassword){
        next(4)
        return
    }
    next()
}

// token的验证 
// 要求前端必须携带token 
// 请
exports.testToken = async (req,res,next) => {
    // 请求头中必须有authorization
    const token = req.headers.authorization
    if(!token){
        next(3)
        return
    }

   const result = await verifyToken(token)

   if(result.code === 0){
        return next(3)
   }

   next()
}